package lovoStudy_9_7.StudentManage;

/**
 * Created with Intellij IDEA
 * Description:
 *
 * @ return:
 * @ author:zxl
 */

import java.util.Scanner;

/**
 * 学生管理系统主界面类
 * */
public class StudentUI {
    public static Scanner scanner = new Scanner(System.in);

    public SuperArray superArray = new SuperArray();


    /**
     * 学生管理系统主程序
     */
    public void UIShow() {
        System.out.println("欢迎来到学生管理系统!");
        menu();
    }

    /**
     * 菜单
     */
    public void menu() {
        while (true) {
            System.out.println("请输入你的选择: 1-增加学生 2-删除学生 3-修改学生 4-查询学生 5-退出程序");
            int input = scanner.nextInt();
            if (input == 1) {
                add();
            } else if (input == 2) {
                remove();
            } else if (input == 3) {
                change();
            } else if (input == 4) {
                get();
            } else if (input == 5) {
                System.out.println("程序退出! 再见");
                return;
            } else {
                System.out.println("输入有误!");
            }

        }
    }


    /**
     * 增加学生
     */

    public void add() {
        System.out.println("请输入学生的名字: ");
        String name = scanner.next();
        System.out.println("请输入学生的年龄: ");
        int age = scanner.nextInt();
        System.out.println("请输入学生的性别: ");
        String gender = scanner.next();
        superArray.add(new Student(name, age, gender));
    }

    /**
     * 减少学生
     */
    public void remove() {
        System.out.println("请输入学生的名字: ");
        String name = scanner.next();
        for (int i = 0; i < superArray.size(); i++) {
            Student student = (Student) superArray.get(i);
            if (student.getName().equals(name)) {
                superArray.remove(i);
                return;
            }
        }
        System.out.println("该学生不存在");


    }

    /**
     * 修改学生
     */
    public void change() {
        System.out.println("请输入学生姓名: ");
        String name = scanner.next();
        for (int i = 0; i < superArray.size(); i++) {
            Student student = (Student) superArray.get(i);
            if (student.getName().equals(name)) {
                System.out.println("请输入该学生的姓名: ");
                String newName = scanner.next();
                System.out.println("请输入该学生的年龄: ");
                int newAge = scanner.nextInt();
                System.out.println("请输入该学生的性别: ");
                String newGender = scanner.next();
               student.setName(newName);
               student.setAge(newAge);
               student.setGender(newGender);
                return;
            }
        }
    }

    /**
     * 查询学生
     */
    public void get() {
        System.out.println("请输入学生姓名: ");
        String name = scanner.next();
        for (int i = 0; i < superArray.size(); i++) {
            Student student = (Student) superArray.get(i);
            if (student.getName().equals(name)) {
                System.out.println("姓名: " + student.getName() + " 学生性别: " + student.getGender() + " 学生年龄: " + student.getAge());
                return;
            }
        }

        System.out.println("该学生不存在");
    }
}